﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Ones.ServiceAccountManagement;

namespace Ones.SysAdmin
{
    public partial class RolesCreator : System.Web.UI.Page
    {
        ServiceAccountManagementClient amc = new ServiceAccountManagementClient("accountBasicHttpBinding");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                successtMsg.Visible = false;
                warningMsg.Visible = false;
                LoadRoles();
            }
        }
        protected void CreateRole_Click(object sender, EventArgs e)
        {
            if (txtRoleName.Text.Length < 3)
            {
                successtMsg.Visible = false;
                warningMsg.Visible = true;
                return;
            }
            bool res = amc.createRole(txtRoleName.Text);
            if (res == true)
            {
                successtMsg.Visible = true;
                warningMsg.Visible = false;
            }
            else
            {
                successtMsg.Visible = false;
                warningMsg.Visible = true;
            }
            txtRoleName.Text = "";
            LoadRoles();
        }

        private void LoadRoles()
        {
            roleList.DataSource = amc.getRoles();
            roleList.DataBind();
        }

        protected void roleList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

        }
    }
}